/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package views;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import models.PacchettoDTO;
import models.PrenotatoDTO;

/**
 *
 * @author simone
 */
public class CellRender extends JLabel implements ListCellRenderer {
  private static final Color HIGHLIGHT_COLOR = new Color(205, 205, 218);

    
    public CellRender(){
        setOpaque(true);
        setIconTextGap(12);
    }

    
    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
    {
        
        if(value.getClass().toString().equals("class models.PacchettoDTO"))
        {
            PacchettoDTO p = null;
            BufferedImage img = null;
            p = (PacchettoDTO) value;
            try {

                URL url = (getClass().getResource("image/no_photo.jpg"));
                img = ImageIO.read(url);
            } catch (IOException e) {

            }

            setIcon(new ImageIcon(img));
            setText(p.getName());
          
        }
        else
        {
            PrenotatoDTO p = null;
            BufferedImage img = null;
            p = (PrenotatoDTO) value;
            try {

                URL url = (getClass().getResource("image/no_photo.jpg"));
                img = ImageIO.read(url);
            } catch (IOException e) {

            } 
            setIcon(new ImageIcon(img));
            setText(p.getName());
        }
        setFont(new Font("Serif", Font.PLAIN, 28));
        if (isSelected) {
            setBackground(HIGHLIGHT_COLOR);
            //setForeground(Color.LIGHT_GRAY);
        } else {
            setBackground(Color.WHITE);
            //setForeground(Color.YELLOW);
        }
        return this;
    }
    
}
